package ru.urfc.portal.model.documents;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import ru.urfc.portal.model.SysObject;
import ru.urfc.portal.ui.client.Constants;

@Entity
@XmlRootElement(name = Constants.ATTACHED_FILE)
public class AttachedFile extends SysObject {
	
	private Document document;
	private String name;
	@Lob @Basic(fetch = FetchType.LAZY)
	@Column(nullable = false)
	private byte[] content;

	public AttachedFile() {
	}

	public AttachedFile(Document document, String name, String content) {
		this.document = document;
		this.name = name;
		this.content = content.getBytes();
	}

	public AttachedFile(Document document, String name) {
		this.document = document;
		this.name = name;
	}

	@XmlTransient
	public Document getDocument() {
		return document;
	}

	@XmlElement
	public String getName() {
		return name;
	}
	
	@XmlTransient
	public byte[] getContent() {
		return content;
	}	

}
